package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.CommunityInteraction;
import com.ruoyi.community.service.ICommunityInteractionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区互动Controller
 * 
 * @author Sea
 * @date 2025-01-02
 */
@DataSource(DataSourceType.SLAVE)
@RestController
@RequestMapping("/community/interaction")
public class CommunityInteractionController extends BaseController
{
    @Autowired
    private ICommunityInteractionService communityInteractionService;

    /**
     * 查询社区互动列表
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityInteraction communityInteraction)
    {
        startPage();
        List<CommunityInteraction> list = communityInteractionService.selectCommunityInteractionList(communityInteraction);
        return getDataTable(list);
    }

    /**
     * 导出社区互动列表
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:export')")
    @Log(title = "社区互动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityInteraction communityInteraction)
    {
        List<CommunityInteraction> list = communityInteractionService.selectCommunityInteractionList(communityInteraction);
        ExcelUtil<CommunityInteraction> util = new ExcelUtil<CommunityInteraction>(CommunityInteraction.class);
        util.exportExcel(response, list, "社区互动数据");
    }

    /**
     * 获取社区互动详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:query')")
    @GetMapping(value = "/{interactionId}")
    public AjaxResult getInfo(@PathVariable("interactionId") Long interactionId)
    {
        return success(communityInteractionService.selectCommunityInteractionByInteractionId(interactionId));
    }

    /**
     * 新增社区互动
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:add')")
    @Log(title = "社区互动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityInteraction communityInteraction)
    {
        return toAjax(communityInteractionService.insertCommunityInteraction(communityInteraction));
    }

    /**
     * 修改社区互动
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:edit')")
    @Log(title = "社区互动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityInteraction communityInteraction)
    {
        return toAjax(communityInteractionService.updateCommunityInteraction(communityInteraction));
    }

    /**
     * 删除社区互动
     */
    @PreAuthorize("@ss.hasPermi('community:interaction:remove')")
    @Log(title = "社区互动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{interactionIds}")
    public AjaxResult remove(@PathVariable Long[] interactionIds)
    {
        return toAjax(communityInteractionService.deleteCommunityInteractionByInteractionIds(interactionIds));
    }
}
